Context = ($view)->
	data = null

	statusTranslate = (status)->
		switch status
			when "新建" then "todo"
			when "开发中" then "in-progress"
			when "开发完成" then "ready-for-test"
			when "解决" then "done"
			when "拒绝" then "refuse"
			when "反馈" then "feedback"

	render = ->
		for task in data
			for key,val of task
				status = val if key is "status"
				id = val if key is "id"
				name = val if key is "name"
				desc = val if key is "desc"
			status = statusTranslate status
			$task = $("<div>",
				class: "task"
				taskId: id
				html: "<div>#{name}</div><div>#{desc}</div>")
			.appendTo $(".#{status} .task-content", $view);
			$task.data "task", data
		$(".task", $view).draggable({ snap: true })

	#test data
	json =
	{
		id: 111,
		name: "问题1",
		type: "BUG",
		level: "正常",
		status: "新建",
		desc: "问题描述问题描述",
		details: "- - -",
		comment: "- - -",
		createTime: TS.api.formatDate(),
		modifyTime: TS.api.formatDate(),
		version: "1.0",
		publishTime: TS.api.formatDate()
	}

	data = [json, json, json, json, json]

	render()

	exports = {}
	exports.dispose = ->
		$view.remove()

	return exports

Tasks = ->
	exports = {}
	ctx = null

	exports.show = ->
		TS.api.promiseView("tasks").then ($view)->
			ctx = new Context $view

	exports.hide = ->
		ctx?.dispose()
		ctx = null

	return exports

TS.views.tasks = new Tasks
